package zero.tech.games.phz.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.stereotype.Service;

import zero.tech.core.data.KeyVal;
import zero.tech.core.data.Resp;
import zero.tech.core.util.StringHelper;
import zero.tech.core.work.WorkManager;
import zero.tech.games.common.BigCalSource;
import zero.tech.games.common.Code;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.common.RoomCache;
import zero.tech.games.logic.data.RoomStatus;
import zero.tech.games.logic.data.consts.LOGICCMD;
import zero.tech.games.logic.data.res.ResReconnet;
import zero.tech.games.logic.util.LogicUtil;
import zero.tech.games.logic.util.PckUtil;
import zero.tech.games.phz.data.PhzConfig;
import zero.tech.games.phz.data.PhzGameBase;
import zero.tech.games.phz.data.PhzRoomCache;
import zero.tech.games.phz.data.PhzSmallPanel;
import zero.tech.games.phz.data.PhzTimer;
import zero.tech.games.phz.data.consts.BrokerType;
import zero.tech.games.phz.data.consts.CphOp;
import zero.tech.games.phz.data.consts.DataType;
import zero.tech.games.phz.data.consts.DelayTime;
import zero.tech.games.phz.data.consts.DelayType;
import zero.tech.games.phz.data.consts.HuType;
import zero.tech.games.phz.data.consts.OpType;
import zero.tech.games.phz.data.consts.PHZCMD;
import zero.tech.games.phz.data.entity.Broker;
import zero.tech.games.phz.data.entity.Card;
import zero.tech.games.phz.data.entity.Data;
import zero.tech.games.phz.data.entity.DelayOp;
import zero.tech.games.phz.data.entity.OpData;
import zero.tech.games.phz.data.entity.PlayerData;
import zero.tech.games.phz.data.entity.PlayerSmallCal;
import zero.tech.games.phz.data.entity.SetcardsPanel;
import zero.tech.games.phz.data.entity.data.ChiData;
import zero.tech.games.phz.data.entity.data.ChouweiData;
import zero.tech.games.phz.data.entity.data.PaopaiData;
import zero.tech.games.phz.data.entity.data.PengData;
import zero.tech.games.phz.data.entity.data.TipaiData;
import zero.tech.games.phz.data.entity.data.WeipaiData;
import zero.tech.games.phz.data.entity.op.CphOpData;
import zero.tech.games.phz.data.entity.op.HupaiData;
import zero.tech.games.phz.data.notify.NotifyGameStart;
import zero.tech.games.phz.data.req.ReqChipai;
import zero.tech.games.phz.data.req.ReqGuopai;
import zero.tech.games.phz.data.req.ReqHupai;
import zero.tech.games.phz.data.req.ReqHupaiGuo;
import zero.tech.games.phz.data.req.ReqOp;
import zero.tech.games.phz.data.req.ReqPengpai;
import zero.tech.games.phz.service.api.IPhzService;
import zero.tech.games.phz.util.CardUtil;
import zero.tech.games.phz.util.PackageUtil;
import zero.tech.games.phz.util.PlaybackUtil;
import zero.tech.games.phz.util.RoomUtil;
import zero.tech.games.phz.work.sync.GameOverCalculateSyncWork;
import zero.tech.wsnet.controller.LogicController;
import zero.tech.wsnet.data.Message;

@Service
public class PhzServiceImpl implements IPhzService{

	@Override
	public void bigCalculate(Room room, int bigcalsource) {
		room.setRoom_status(RoomStatus.CALCULATING);
		WorkManager.getManager().submit(GameOverCalculateSyncWork.class,room,bigcalsource);			
	}

	@Override
	public ResReconnet roomReconnect(Room room, LogicController online) {
		ResReconnet resReconnet=PackageUtil.packageResPdkReconnect(room,online);
		return resReconnet;
	}

	@Override
	public void roomTimer(Room room) {
		int room_status=room.getRoom_status();
		if(room_status==RoomStatus.DEFAULT) {
			RoomUtil.checkGameStart(room);
		}else if(room_status==RoomStatus.GAMING){
			long now=System.currentTimeMillis();
			PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
			PhzConfig phzConfig = (PhzConfig) room.getGameConfig();
			if(phzConfig.getAuto_deposit()>0) {
				if(phzGameBase.getStep()==1) {
					//出牌
					int dispatch_uid=phzGameBase.getDispatch_uid();
					PlayerData dispatch_data=phzGameBase.getPlayers().get(dispatch_uid);
					long lastDispatchTime=dispatch_data.getLast_outcard_time();
					if(phzGameBase.getAuto_deposit().containsKey(dispatch_uid)) {
						if(now-lastDispatchTime>=3*1000) {
							//托管出牌
							autoDepositOutcard(room,dispatch_uid);
							return;
						}
					}else {
						if(now-lastDispatchTime>=phzConfig.getAuto_deposit()*1000) {
							//进入托管
							phzGameBase.getAuto_deposit().put(dispatch_uid, now);
							//广播某人进入托管
							LogicUtil.broadRoomAllControllersInclude(room, Message.build(LOGICCMD.NOTIFY_ENTER_AUTODEPOSIT, Resp.build(Code.OK, "进入托管",PckUtil.packageNotifyEnterAutoDeposit(dispatch_uid,now))));
						}
					}
				}else if(phzGameBase.getStep()==2) {
					//操作
					Map<Integer, List<CphOpData>> oplistmap=phzGameBase.getOplistmap();
					Map<Integer, ReqOp> choosemap=phzGameBase.getChoosemap();
					if(!oplistmap.isEmpty()) {
						boolean flag=false;
						for(Entry<Integer,List<CphOpData>> entry:oplistmap.entrySet()) {
							int uid=entry.getKey();
							if(!choosemap.containsKey(uid)) {
								//没有做出选择
								PlayerData pData=phzGameBase.getPlayers().get(uid);
								long time=pData.getLast_cphop_time();
								if(phzGameBase.getAuto_deposit().containsKey(uid)) {
									if(now-time>=3*1000) {
										autoDepositOp(room,uid);
										flag=true;
									}
								}else {
									if(now-time>=phzConfig.getAuto_deposit()*1000) {
										//进入托管
										phzGameBase.getAuto_deposit().put(uid, now);
										//广播某人进入托管
										LogicUtil.broadRoomAllControllersInclude(room, Message.build(LOGICCMD.NOTIFY_ENTER_AUTODEPOSIT, Resp.build(Code.OK, "进入托管",PckUtil.packageNotifyEnterAutoDeposit(uid,now))));
									}
								}
							}
						}
						if(flag) {
							return;
						}
					}
				}
			}
			DelayOp delayOp=phzGameBase.getDelayOp();
			if(delayOp!=null) {
				delayOp(room,delayOp);
			}
			
			
		}else if(room_status==RoomStatus.WAIT_NEXT_ROUND){
			RoomUtil.checkGameStart(room);
		}else if(room_status==RoomStatus.CALCULATING) {
			
		}
	}

	private void autoDepositOp(Room room, int uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		Map<Integer, List<CphOpData>> oplistmap=phzGameBase.getOplistmap();
		LogicController controller=room.getAllControllers().get(uid);
		List<CphOpData> cphOpDatas=oplistmap.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(CphOp.PASS,cphOpDatas);
		if(cphOpData!=null) {
			OpData opData=phzGameBase.getFanpai();
			ReqGuopai reqGuopai = new ReqGuopai();
			reqGuopai.setOp(CphOp.PASS);
			reqGuopai.setUid(uid);
			RoomUtil.reqGuopai(room, controller, reqGuopai, opData);
			return;
		}
	}

	private void autoDepositOutcard(Room room, int uid) {
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(uid);		
		List<Card> cards=playerData.getHands();
		Integer card_id=null;
		Map<Integer,Integer> nummap=CardUtil.numMap(cards);
		List<KeyVal<Integer, Integer>> kvs=StringHelper.parseMapToList(nummap);
		Collections.sort(kvs,new Comparator<KeyVal<Integer, Integer>>() {

			@Override
			public int compare(KeyVal<Integer, Integer> o1, KeyVal<Integer, Integer> o2) {
				return o1.getV()-o2.getV();
			}
		});
		for(KeyVal<Integer, Integer> kv:kvs) {
			if(kv.getV()==1||kv.getV()==2) {
				card_id=kv.getK();
				break;
			}
		}
		if(card_id==null) {
			throw new RuntimeException("自动托管打牌逻辑出错,检查逻辑");
		}
		Card one=CardUtil.findOneCardFromHandByCardId(cards, card_id);
		LogicController logicController = room.getAllControllers().get(uid);
		outcard(room, logicController, playerData, one);
	}

	private void delayOp(Room room, DelayOp delayOp) {
		PhzGameBase phzGameBase= (PhzGameBase) room.getGameBase();
		long now=System.currentTimeMillis();
		int op=delayOp.getType();
		int delay=delayOp.getDelay();
		long time=delayOp.getTime();
		int uid=delayOp.getUid();
		if(now-time>=delay*1000) {
			if(op==DelayType.AUTO_MOPAI) {
				phzGameBase.setDelayOp(null);
				autoMopai(room, uid);
			}else if(op==DelayType.FAPAI_TIPAI) {
				phzGameBase.setDelayOp(null);
				fapaiTipai(room,uid);
			}else if(op==DelayType.AUTO_PAOPAI) {
				phzGameBase.setDelayOp(null);
				PaopaiData paopaiData=(PaopaiData) delayOp.getObjs()[0];
				int opType=(int) delayOp.getObjs()[1];
				Card card=null;
				if(opType==OpType.MOPAI) {
					card=(Card) delayOp.getObjs()[2];
				}
				autoPaopai(room,paopaiData,card);
			}else if(op==DelayType.AUTO_TIPAI) {
				phzGameBase.setDelayOp(null);
				TipaiData tipaiData = (TipaiData) delayOp.getObjs()[0];
				int opType=(int) delayOp.getObjs()[1];
				Card card=null;
				if(opType==OpType.MOPAI) {
					card=(Card) delayOp.getObjs()[2];
				}
				autoTipai(room,tipaiData,card);
			}else if(op==DelayType.AUTO_WEIPAI) {
				phzGameBase.setDelayOp(null);
				WeipaiData weipaiData= (WeipaiData) delayOp.getObjs()[0];
				int opType=(int) delayOp.getObjs()[1];
				Card card=null;
				if(opType==OpType.MOPAI) {
					card=(Card) delayOp.getObjs()[2];
				}
				autoWeipai(room,weipaiData,card);
			}else if(op==DelayType.AUTO_CHOUWEI) {
				phzGameBase.setDelayOp(null);
				ChouweiData chouweiData= (ChouweiData) delayOp.getObjs()[0];
				int opType=(int) delayOp.getObjs()[1];
				Card card=null;
				if(opType==OpType.MOPAI) {
					card=(Card) delayOp.getObjs()[2];
				}
				autoChouwei(room,chouweiData,card);
			}else if(op==DelayType.CPH_CHECK) {
				autoCheckCph(room);
			}
		}
		
	}
	
	private void autoCheckCph(Room room) {
		RoomUtil.autoCheckCph(room);
	}


	private void autoChouwei(Room room, ChouweiData chouweiData, Card card) {
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "臭偎",PackageUtil.packageNotifyBaipai(room,chouweiData.getUid(),chouweiData))));
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		if(card!=null) {
			boolean ok=doSelftBaipaiHupai(room,chouweiData.getUid());
			if(ok) {
				RoomUtil.hupai(room, chouweiData.getUid(), null);
				return;
			}
			Map<Integer,List<CphOpData>> map1=RoomUtil.doSelftMopaiBaipaiAndHupaiOps(room,chouweiData.getUid(),null);
			if(!map1.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_CHOUWEI_BEI_HUPAI_DADUAN,chouweiData.getUid()));
				phzGameBase.getBroker().getParams().put("hu", phzGameBase.getFanpai());
				RoomUtil.autoCph(room,map1);
				return;
			}
		}
		RoomUtil.chouwei(room, chouweiData.getUid());
	}


	private void autoWeipai(Room room, WeipaiData weipaiData, Card card) {
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "偎牌",PackageUtil.packageNotifyBaipai(room,weipaiData.getUid(),weipaiData))));
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		if(card!=null) {
			boolean ok=doSelftBaipaiHupai(room,weipaiData.getUid());
			if(ok) {
				RoomUtil.hupai(room, weipaiData.getUid(), null);
				return;
			}
			Map<Integer,List<CphOpData>> map1=RoomUtil.doSelftMopaiBaipaiAndHupaiOps(room,weipaiData.getUid(),null);
			if(!map1.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_WEIPAI_BEI_HUPAI_DADUAN,weipaiData.getUid()));
				phzGameBase.getBroker().getParams().put("hu", phzGameBase.getFanpai());
				RoomUtil.autoCph(room,map1);
				return;
			}
		}
		RoomUtil.weipai(room,weipaiData.getUid());
	}

	private boolean doSelftBaipaiHupai(Room room, int uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData= phzGameBase.getPlayers().get(uid);
		if(playerData.getHands().isEmpty()&&!playerData.isQihu()) {
			return true;
		}
		return false;
	}

	private void autoTipai(Room room, TipaiData tipaiData, Card card) {
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,tipaiData.getUid(),tipaiData))));
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		if(card!=null) {
			boolean ok=doSelftBaipaiHupai(room,tipaiData.getUid());
			if(ok) {
				RoomUtil.hupai(room, tipaiData.getUid(), null);
				return;
			}
			Map<Integer,List<CphOpData>> map1=RoomUtil.doSelftMopaiBaipaiAndHupaiOps(room,tipaiData.getUid(),null);
			if(!map1.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_TIPAI_BEI_HUPAI_DADUAN,tipaiData.getUid()));
				phzGameBase.getBroker().getParams().put("hu", phzGameBase.getFanpai());
				RoomUtil.autoCph(room,map1);
				return;
			}
		}
		RoomUtil.tipai(room,tipaiData.getUid());
	}

	private void autoPaopai(Room room, PaopaiData paopaiData, Card card) {
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "跑牌",PackageUtil.packageNotifyBaipai(room,paopaiData.getUid(),paopaiData))));
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		if(card!=null) {
			boolean ok=doSelftBaipaiHupai(room,paopaiData.getUid());
			if(ok) {
				RoomUtil.hupai(room, paopaiData.getUid(), null);
				return;
			}
			Map<Integer,List<CphOpData>> map1=RoomUtil.doSelftMopaiBaipaiAndHupaiOps(room,paopaiData.getUid(),null);
			if(!map1.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_PAOPAI_BEI_HUPAI_DADUAN,paopaiData.getUid()));
				phzGameBase.getBroker().getParams().put("hu", phzGameBase.getFanpai());
				RoomUtil.autoCph(room,map1);
				return;
			}
		}
		RoomUtil.paopai(room,paopaiData.getUid());
	}

	private void fapaiTipai(Room room, int uid) {
		PhzGameBase phzGameBase=(PhzGameBase) room.getGameBase();
		PhzConfig phzConfig = (PhzConfig) room.getGameConfig();
		List<TipaiData> tipaiDatas=RoomUtil.doTipais(room,uid);
		if(!tipaiDatas.isEmpty()) {
			LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,uid,tipaiDatas))));
		}
		phzGameBase.getOperateDatas().add(PackageUtil.packageZhanjiBaipai(uid,tipaiDatas));
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		CphOpData cphOpData=RoomUtil.checkHupaiOp(playerData, null,phzConfig.getHupai_need());
		if(cphOpData!=null) {
			RoomUtil.hupai(room, uid,null);
			return;
		}
		if(tipaiDatas.size()==5) {
			RoomUtil.hupai(room, uid,null);
			return;
		}
		if(tipaiDatas.size()==3) {
			Card bu_card=phzGameBase.getDipai().remove(0);
			playerData.getHands().add(bu_card);
			LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_YADI, Resp.build(Code.OK, "某人压底",PackageUtil.packageNotifyYadi(room,uid,bu_card))));
			//补牌之后可能继续提牌
			List<TipaiData> tipais=RoomUtil.doTipais(room, uid);
			if(!tipais.isEmpty()) {
				//4
				LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,uid,tipais))));
				bu_card=phzGameBase.getDipai().remove(0);
				playerData.getHands().add(bu_card);
				LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_YADI, Resp.build(Code.OK, "某人压底",PackageUtil.packageNotifyYadi(room,uid,bu_card))));
				tipais=RoomUtil.doTipais(room, uid);
				if(!tipais.isEmpty()) {
					//5
					RoomUtil.hupai(room, uid,null);
					return;
				}
			}
		}
		if(tipaiDatas.size()>=2) {
			int next_uid=LogicUtil.getNextPosByUid(room,uid);
			phzGameBase.setDelayOp(new DelayOp(next_uid, DelayType.AUTO_MOPAI, DelayTime.AUTO_MOPAI_DELAY));
			return;
		}
		RoomUtil.notifyOutCard(room,uid);		
	}

	@Override
	public void gameStart(Room room) {
		initRoomBasic(room);
		initHandCards(room);
		initSmallPanel(room);
		confirmBanker(room);
		notifyGameStart(room);
	}


	private void notifyGameStart(Room room) {
		for(LogicController logicController:room.getAllControllers().values()) {
			NotifyGameStart notifyGameStart=PackageUtil.packageNotifyGameStart(room,logicController);
			logicController.getWebClient().sendMessage(Message.build(PHZCMD.NOTIFY_GAME_START, Resp.build(Code.OK, "通知游戏开始",notifyGameStart)));
		}
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		int banker_uid=phzGameBase.getBanker_uid();
		phzGameBase.setDelayOp(new DelayOp(banker_uid, DelayType.FAPAI_TIPAI, DelayTime.FAPAI_TIPAI_DELAY));
	}
	
	@Override
	public void autoMopai(Room room, int uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		int flag=qishouXianjiaTipaiAndYadi(room);
		if(flag==1) {
			phzGameBase.setDelayOp(new DelayOp(uid, DelayType.AUTO_MOPAI, DelayTime.AUTO_MOPAI_DELAY));
			return;
		}else if(flag==2) {
			//游戏结束
			return;
		}
		List<Card> dipais=phzGameBase.getDipai();
		if(dipais.isEmpty()) {
			//底牌被摸完了,则直接结束
			gameOver(room,null);
			return;
		}
		System.out.println("系统自动摸牌============");
		Card card=dipais.remove(0);
		phzGameBase.setDispatch_uid(uid);
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_CHANGE_PLAYER, Resp.build(Code.OK, "摸牌-换人",PackageUtil.packageNotifyChangePlayer(room, OpType.MOPAI, card))));
		OpData opData=new OpData(uid, OpType.MOPAI, card);
		phzGameBase.setFanpai(opData);
		
		//如果该牌自己可以提,别人不可以胡牌,否则优先检测胡牌
		if(!selfTipaiOrWeipai(room,uid,card)) {
			Map<Integer,List<CphOpData>> map=RoomUtil.doMopaiHupaiOps(room,uid,card);
			if(!map.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_MOPAI_BEI_HUPAI_DADUAN,uid));
				phzGameBase.getBroker().getParams().put("card", card);
				phzGameBase.getBroker().getParams().put("opData", opData);
				RoomUtil.autoCph(room,map);
				return;
			}
		}else {
			Map<Integer,List<CphOpData>> map=RoomUtil.doSelftMopaiBaipaiAndHupaiOps(room, uid, card);
			if(!map.isEmpty()) {
				phzGameBase.setBroker(new Broker(BrokerType.AUTO_MOPAI_BEI_HUPAI_DADUAN,uid));
				phzGameBase.getBroker().getParams().put("card", card);
				phzGameBase.getBroker().getParams().put("opData", opData);
				RoomUtil.autoCph(room,map);
				return;
			}
		}
		
		RoomUtil.mopai(room,uid,card,opData,true);
	}



	private boolean selfTipaiOrWeipai(Room room, int uid, Card card) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData= phzGameBase.getPlayers().get(uid);
		List<Card> hands=playerData.getHands();
		int count=CardUtil.findCount(hands, card);

		if(count==3||count==2) {
			return true;
		}
		List<Data> datas=playerData.getBaipais();
		for(Data data:datas) {
			if(data.getType()==DataType.WEIPAI) {
				WeipaiData weipaiData = (WeipaiData) data;
				if(weipaiData.getWeipailist().get(0).getCard_id()==card.getCard_id()) {
					return true;
				}
			}
		}
		return false;
	}

	private int qishouXianjiaTipaiAndYadi(Room room) {
		int flag=0;
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		if(!phzGameBase.isQishouxianjiatipaiandyadi()) {
			for(LogicController logicController:room.getAllControllers().values()) {
				int uid=logicController.getId();
				flag=qishouXianjiaTipaiAndYadi(room, uid);
				if(flag==2) {
					return flag;
				}
			}	
			phzGameBase.setQishouxianjiatipaiandyadi(true);
		}
		return flag;
	}
	
	private int qishouXianjiaTipaiAndYadi(Room room,int uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		int banker_uid=phzGameBase.getBanker_uid();
		if(uid!=banker_uid) {
			List<TipaiData> tipaiDatas=RoomUtil.doTipais(room,uid);
			if(!tipaiDatas.isEmpty()) {
				LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,uid,tipaiDatas))));
				if(tipaiDatas.size()==5) {
					RoomUtil.hupai(room, uid,null);
					return 2;
				}
				if(tipaiDatas.size()==2) {
					PlayerData xianjiaData = phzGameBase.getPlayers().get(uid);
					Card bu_card=phzGameBase.getDipai().remove(0);
					xianjiaData.getHands().add(bu_card);
					LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_YADI, Resp.build(Code.OK, "某人压底",PackageUtil.packageNotifyYadi(room,uid,bu_card))));
					//补牌之后可能继续提牌
					List<TipaiData> tipais=RoomUtil.doTipais(room, uid);
					if(!tipais.isEmpty()) {
						//3
						LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,uid,tipais))));
						bu_card=phzGameBase.getDipai().remove(0);
						xianjiaData.getHands().add(bu_card);
						LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_YADI, Resp.build(Code.OK, "某人压底",PackageUtil.packageNotifyYadi(room,uid,bu_card))));
						tipais=RoomUtil.doTipais(room, uid);
						if(!tipais.isEmpty()) {
							//4
							LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_BAIPAI, Resp.build(Code.OK, "提牌",PackageUtil.packageNotifyBaipai(room,uid,tipais))));
							bu_card=phzGameBase.getDipai().remove(0);
							xianjiaData.getHands().add(bu_card);
							LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_YADI, Resp.build(Code.OK, "某人压底",PackageUtil.packageNotifyYadi(room,uid,bu_card))));
							tipais=RoomUtil.doTipais(room, uid);
							if(!tipais.isEmpty()) {
								//5
								RoomUtil.hupai(room, uid,null);
								return 2;
							}
						}
					}
					return 1;
				}
			}
		}
		return 0;
	}


	private void confirmBanker(Room room) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		Map<Integer, LogicController> controllers=room.getAllControllers();
		List<Integer> uids=new ArrayList<>();
		uids.addAll(controllers.keySet());
//		Collections.shuffle(uids);
		Collections.sort(uids,new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o1-o2;
			}
		});
		int banker_uid=uids.get(0);
		phzGameBase.setBanker_uid(banker_uid);
		Card banker_last_card=phzGameBase.getDipai().remove(0);
		phzGameBase.setBanker_last_card(banker_last_card);
		phzGameBase.getPlayers().get(banker_uid).getHands().add(banker_last_card);
		
		//处理战绩数据
		phzGameBase.getOperateDatas().add(PackageUtil.packageZhanjiBankerLastCard(banker_uid,banker_last_card));
	}

	private void initSmallPanel(Room room) {
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		int room_times=room.getRoom_times();
		String room_id=room.getRoom_id();
		String configStr=room.getConfigStr();
		PhzSmallPanel phzSmallPanel = new PhzSmallPanel();
		phzSmallPanel.setRoom_id(room_id);
		phzSmallPanel.setConfigStr(configStr);		
		phzRoomCache.getSmallPanels().put(room_times, phzSmallPanel);		
	}

	private void initHandCards(Room room) {
		PhzRoomCache pdkRoomCache = (PhzRoomCache) room.getRoomCache();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PhzConfig phzConfig = (PhzConfig) room.getGameConfig();
		Map<Integer, LogicController> controllers=room.getAllControllers();
		SetcardsPanel setcardsPanel = pdkRoomCache.getSetcardsPanel();
		Map<Integer, List<Integer>> setsmap =setcardsPanel.getSetsmap();
		List<Card> deck=new ArrayList<>();
		deck.addAll(CardUtil.phz());
		Collections.shuffle(deck);
		int num=room.getAllControllers().size();
		if(num==2&&phzConfig.getZhaipai()==1) {
			List<Card>zhaipai=new ArrayList<>();
			zhaipai.addAll(deck.subList(0, 20));
			deck.removeAll(zhaipai);
			setsmap.clear();
		}
		List<Integer> uids=new ArrayList<>();
		uids.addAll(controllers.keySet());
		Collections.shuffle(uids);
		int length=20;
		if(!setsmap.isEmpty()) {
			//配牌器发牌
			List<Integer> setcard_uids=new ArrayList<>();
			for(Entry<Integer,List<Integer>> entry:setsmap.entrySet()) {
				int uid=entry.getKey();
				if(uids.contains(uid)){
					List<Integer> cardIds=entry.getValue();
					List<Card> hands=new ArrayList<>();
					for(Integer card_id:cardIds) {
						Card card=CardUtil.findOneCardFromHandByCardId(deck, card_id);
						deck.remove(card);
						hands.add(card);
					}
					PlayerData playerData=new PlayerData(uid,hands);
					phzGameBase.getPlayers().put(uid,playerData);
					phzGameBase.getHandsmap().put(uid, hands);//战绩使用
					setcard_uids.add(uid);
				}
			}
			uids.removeAll(setcard_uids);
			for(int i=0;i<uids.size();i++) {
				int uid=uids.get(i);
				List<Card> hands=new ArrayList<>();
				hands.addAll(deck.subList(0, length));
				PlayerData playerData=new PlayerData(uid,hands);
				phzGameBase.getPlayers().put(uid,playerData);
				phzGameBase.getHandsmap().put(uid, hands);//战绩使用
				deck.removeAll(hands);
			}
			List<Card> dipai=new ArrayList<>();
			dipai.addAll(deck);
			phzGameBase.getDipai().addAll(dipai);
			phzGameBase.setDipai_count(dipai.size());
			
			pdkRoomCache.setSetcardsPanel(new SetcardsPanel());//清除设置面板
		}else {
			//随机发牌
			for(int i=0;i<uids.size();i++) {
				int uid=uids.get(i);
				List<Card> hands=new ArrayList<>();
				hands.addAll(deck.subList(0,length));
				PlayerData playerData=new PlayerData(uid,hands);
				phzGameBase.getPlayers().put(uid,playerData);
				phzGameBase.getHandsmap().put(uid, hands);//战绩使用
				deck.removeAll(hands);
			}
			List<Card> dipai=new ArrayList<>();
			dipai.addAll(deck);
			phzGameBase.getDipai().addAll(dipai);
			phzGameBase.setDipai_count(dipai.size());
		}
	}

	private void initRoomBasic(Room room) {
		PhzTimer phzTimer=(PhzTimer) room.getTimer();
		room.setRoom_status(RoomStatus.GAMING);
		room.setRoom_times(room.getRoom_times()+1);
		phzTimer.lastDispatchTime=System.currentTimeMillis();		
	}

	@Override
	public void reqOutCard(Room room, LogicController controller, int id) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		if(phzGameBase.getDispatch_uid()!=uid) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		Map<Integer, List<CphOpData>> map=phzGameBase.getOplistmap();
		if(!map.isEmpty()&&!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(!map.isEmpty()&&map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(!choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.CANT_OPERATE, "还未操作")));
				return;
			}
		}
		OpData opData = phzGameBase.getFanpai();
		if(opData!=null&&opData.getType()==OpType.OUTCARD&&opData.getUid()==uid) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.CANT_OPERATE, "你已经打过牌了")));
			return;
		}
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		List<Card> hands=playerData.getHands();
		Card card=CardUtil.findFromCardsById(hands, id);
		if(card==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.PARAM_ERROR, "参数错误")));
			return;
		}
		List<Card>cards=CardUtil.findFromHandByCardId(hands, card.getCard_id());
		if(cards.size()>=3) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.PARAM_ERROR, "3张以上不可打")));
			return;
		}
		outcard(room,controller,playerData,card);
	}

	private void outcard(Room room,LogicController controller, PlayerData playerData, Card card) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		int uid=playerData.getUid();
		controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_OUTCARD, Resp.build(Code.OK, "出牌成功",PackageUtil.packageResOutCard(uid,card))));
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_OUTCARD, Resp.build(Code.OK, "通知出牌",PackageUtil.packageNotifyOutCard(uid,card))),controller);
		int flag=qishouXianjiaTipaiAndYadi(room);
		if(flag==2) {
			//游戏结束
			return;
		}
		int next_uid=LogicUtil.getNextPosByUid(room, uid);
		playerData.getQipenglist().add(card.getCard_id());
		playerData.getQichilist().add(card.getCard_id());
		playerData.getHands().remove(card);
		playerData.setOut_count(playerData.getOut_count()+1);//出牌次数+1
		OpData opData =new OpData(uid, OpType.OUTCARD, card);	
		phzGameBase.setFanpai(opData);
		
		//放炮罚打牌自动胡牌
		CphOpData hupai=RoomUtil.doFangpaofaHupaiOp(room,card,uid);
		if(hupai!=null) {
			RoomUtil.hupai(room, hupai.getUid(),opData);
			return;
		}
		
		
		Data data =RoomUtil.doBaipai(room,card,uid,OpType.OUTCARD);
		if(data!=null) {
			phzGameBase.getFanpai().setBaipai_uid(data.getUid());
			if(data instanceof PaopaiData) {
				PaopaiData paopaiData = (PaopaiData) data;
				PlayerData pData=phzGameBase.getPlayers().get(paopaiData.getUid());
				int paoSize=pData.paoPaiSize();
				if(paoSize<=1) {
					hupai=RoomUtil.fangpaofaHupaiOp(room,null,paopaiData.getUid());
					if(hupai!=null) {
						RoomUtil.hupai(room, hupai.getUid(),null);
						return;
					}
				}
				phzGameBase.setDelayOp(new DelayOp(paopaiData.getUid(), DelayType.AUTO_PAOPAI, DelayTime.AUTO_PAOPAI_DELAY, paopaiData,OpType.OUTCARD));
			}else if(data instanceof TipaiData) {
				TipaiData tipaiData=(TipaiData) data;
				PlayerData pData=phzGameBase.getPlayers().get(tipaiData.getUid());
				int paoSize=pData.paoPaiSize();
				if(paoSize<=1) {
					hupai=RoomUtil.fangpaofaHupaiOp(room,null,tipaiData.getUid());
					if(hupai!=null) {
						RoomUtil.hupai(room, hupai.getUid(),null);
						return;
					}
				}
				phzGameBase.setDelayOp(new DelayOp(tipaiData.getUid(), DelayType.AUTO_TIPAI, DelayTime.AUTO_TIPAI_DELAY, tipaiData,OpType.OUTCARD));
			}else if(data instanceof WeipaiData) {
				WeipaiData weipaiData=(WeipaiData) data;
				hupai=RoomUtil.fangpaofaHupaiOp(room,null,weipaiData.getUid());
				if(hupai!=null) {
					RoomUtil.hupai(room, hupai.getUid(),null);
					return;
				}
				phzGameBase.setDelayOp(new DelayOp(weipaiData.getUid(), DelayType.AUTO_WEIPAI, DelayTime.AUTO_WEIPAI_DELAY, weipaiData,OpType.OUTCARD));
			}else if(data instanceof ChouweiData) {
				ChouweiData chouweiData=(ChouweiData) data;
				hupai=RoomUtil.fangpaofaHupaiOp(room,null,chouweiData.getUid());
				if(hupai!=null) {
					RoomUtil.hupai(room, hupai.getUid(),null);
					return;
				}
				phzGameBase.setDelayOp(new DelayOp(chouweiData.getUid(), DelayType.AUTO_CHOUWEI, DelayTime.AUTO_CHOUWEI_DELAY, chouweiData,OpType.OUTCARD));
			}
			return;
		}
		Map<Integer,List<CphOpData>> map=RoomUtil.doCphOps(room,card,uid,OpType.OUTCARD,true);
		if(!map.isEmpty()) {
			RoomUtil.autoCph(room, map);
			return;
		}
		phzGameBase.setStep(0);
		playerData.getOp_datas().add(opData);
		phzGameBase.setDelayOp(new DelayOp(next_uid, DelayType.AUTO_MOPAI,flag==1?DelayTime.AUTO_BUPAI_DELAY:DelayTime.AUTO_MOPAI_DELAY));
	}



	@Override
	public void reqHupai(Room room, LogicController controller, ReqHupai reqHupai, int op) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PhzConfig phzConfig = (PhzConfig) room.getGameConfig();
		
		OpData opData=phzGameBase.getFanpai();
		if(opData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		
		Card card=null;
		if(opData.getBaipai_uid()!=null&&opData.getBaipai_uid().intValue()==uid) {
			//被自己摆牌了
		}else {
			card=opData.getCard();
		}
		
		Map<Integer,List<CphOpData>> map=phzGameBase.getOplistmap();
		if(map.isEmpty()||!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "已经做出选择")));
				return;
			}
		}
		List<CphOpData>cphOpDatas =map.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(op,cphOpDatas);
		if(cphOpData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "参数错误,没有该操作")));
			return;
		}
		//检测手里是否都有请求的牌
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		CphOpData hu=RoomUtil.checkHupaiOp(playerData, card,phzConfig.getHupai_need());
		if(hu==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "不能胡牌")));
			return;
		}
		RoomUtil.reqHupai(room,controller,reqHupai,opData);		
	}

	@Override
	public void reqPengpai(Room room, LogicController controller, ReqPengpai reqPengpai, int op) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		OpData opData=phzGameBase.getFanpai();
		Map<Integer,List<CphOpData>> map=phzGameBase.getOplistmap();
		if(map.isEmpty()||!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "已经做出选择")));
				return;
			}
		}
		List<CphOpData>cphOpDatas =map.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(op,cphOpDatas);
		if(cphOpData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "参数错误,没有该操作")));
			return;
		}
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		CphOpData peng=RoomUtil.checkPengpaiOp(playerData, opData.getCard());
		if(peng==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "不能碰牌")));
			return;
		}
		RoomUtil.reqPengpai(room,controller,reqPengpai,opData);		
	}

	@Override
	public void reqChipai(Room room, LogicController controller, ReqChipai reqChipai, int op) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		OpData opData=phzGameBase.getFanpai();
		Map<Integer,List<CphOpData>> map=phzGameBase.getOplistmap();
		if(map.isEmpty()||!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "已经做出选择")));
				return;
			}
		}
		List<CphOpData>cphOpDatas =map.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(op,cphOpDatas);
		if(cphOpData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "参数错误,没有该操作")));
			return;
		}
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		CphOpData chi=RoomUtil.checkChipaiOps(playerData, opData.getCard());
		if(chi==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "不能吃牌")));
			return;
		}
		RoomUtil.reqChipai(room,controller,reqChipai,opData);			
	}

	@Override
	public void reqGuopai(Room room, LogicController controller, ReqGuopai reqGuopai, int op) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		OpData opData=phzGameBase.getFanpai();
		Map<Integer,List<CphOpData>> map=phzGameBase.getOplistmap();
		if(map.isEmpty()||!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "已经做出选择")));
				return;
			}
		}
		
		List<CphOpData>cphOpDatas =map.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(op,cphOpDatas);
		if(cphOpData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "参数错误,没有该操作")));
			return;
		}
		RoomUtil.reqGuopai(room,controller,reqGuopai,opData);		
	}

	@Override
	public void gameOver(Room room, LogicController winner) {
		//小结算
		smallCalculate(room,winner);
	}

	private void smallCalculate(Room room, LogicController winner) {
		PhzConfig phzConfig = (PhzConfig) room.getGameConfig();
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		calculateSmallPanel(room);
		
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_SMALL_CALCULATE, Resp.build(Code.OK, "小结算数据",PckUtil.packageNotifySmallCalculate(room))));
		
		//检查是否有玩家的钱不够进行下一轮
		boolean advance_big_calculate=false;
		for(LogicController logicController:room.getAllControllers().values()) {
			boolean ok=RoomUtil.checkMoneyEnoughNextRound(room, logicController);
			if(!ok) {
				advance_big_calculate=true;
				break;
			}
		}
		
		Map<Integer,Integer> score_map=phzRoomCache.getTotal_score();
		for(Integer score:score_map.values()) {
			if(phzConfig.getBig_cal_huxi()!=0&&score.intValue()>=phzConfig.getBig_cal_huxi()) {
				advance_big_calculate=true;
			}
		}
		
		if(advance_big_calculate) {
			bigCalculate(room,BigCalSource.SMALLOVER_BIG_CAL);
		}else {
			smallCalculateReset(room);
		}
	}

	private void smallCalculateReset(Room room) {
		PlaybackUtil.saveClubSmallPlayback(room);//临时保存小局战绩数据
		room.setRoom_status(RoomStatus.WAIT_NEXT_ROUND);
		String room_id=room.getRoom_id();
		PhzGameBase phzGameBase =new PhzGameBase(room_id);
		room.setGameBase(phzGameBase);
		PhzTimer pdkTimer=new PhzTimer(room.getRoom_id());
		room.setTimer(pdkTimer);
		RoomCache roomCache = room.getRoomCache();
		roomCache.getWatchers().clear();//清除观战者
		LogicUtil.broadRoomAllControllersInclude(room, Message.build(PHZCMD.NOTIFY_SMALL_RESET, Resp.build(Code.OK, "小结算重置消息",PckUtil.packageNotifySmallReset(room))));		
	}

	private void calculateSmallPanel(Room room) {
		int room_times=room.getRoom_times();
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		PhzGameBase phzGameBase= (PhzGameBase) room.getGameBase();
		PhzSmallPanel phzSmallPanel = (PhzSmallPanel) phzRoomCache.getSmallPanels().get(room_times);
		phzSmallPanel.setHupai_uid(phzGameBase.getHupai_uid());
		phzSmallPanel.setHu(phzGameBase.getHupai());
		phzSmallPanel.getDipais().addAll(phzGameBase.getDipai());
		phzSmallPanel.setGameOverTime(System.currentTimeMillis());
		phzSmallPanel.setBanker_uid(phzGameBase.getBanker_uid());
		List<PlayerSmallCal> playerCals=smallCalScoreBegin(room);
		phzSmallPanel.getPlayerCals().addAll(playerCals);
		if(phzGameBase.getHupai_uid()!=null) {
			PlayerData hupai_data=phzGameBase.getPlayers().get(phzGameBase.getHupai_uid());
			phzSmallPanel.getHu_types().addAll(hupai_data.getHu_types());
		}
	}

	private List<PlayerSmallCal> smallCalScoreBegin(Room room) {
		List<PlayerSmallCal> list=new ArrayList<>();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		Map<Integer,Integer> score_map=scoreMap(room);
		Map<Integer,PlayerData> playerDatas=phzGameBase.getPlayers();
		for(PlayerData playerData:playerDatas.values()) {
			int uid=playerData.getUid();
			int cur_win_score=score_map.get(uid);
			int total_win_score=phzRoomCache.getTotal_score().get(uid);
			
			LogicController logicController = room.getAllControllers().get(uid);
			PlayerSmallCal playerSmallCal = new PlayerSmallCal();
			playerSmallCal.getHands().addAll(playerData.getHands());
			System.out.println("发送给客户端的手牌数据:"+playerSmallCal.getHands());
			playerSmallCal.getBaipais().addAll(playerData.getBaipais());
			playerSmallCal.setCur_win_score(cur_win_score);
			playerSmallCal.setTotal_win_score(total_win_score);
			playerSmallCal.setSimpleUser(logicController.getSimpleUser());
			list.add(playerSmallCal);
		}
		
		return list;
	}


	private Map<Integer, Integer> scoreMap(Room room) {
		//算分
		Map<Integer, Integer> score_map=new HashMap<>();
		PhzRoomCache phzRoomCache= (PhzRoomCache) room.getRoomCache();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PhzConfig phzConfig= (PhzConfig) room.getGameConfig();
		Map<Integer,PlayerData> playerDatas=phzGameBase.getPlayers();
		int banker_uid=phzGameBase.getBanker_uid();
		Integer hupai_uid=phzGameBase.getHupai_uid();
		if(hupai_uid==null) {
			//流局庄家输流局分数,闲家不输赢
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==banker_uid) {
					score=-phzConfig.getLiuju_zhuang_lose();
				}else {
					score=0;
				}
				
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
			return score_map;
		}
		PlayerData hupai_data=playerDatas.get(hupai_uid);
		boolean tianhu=checkTianhu(room,hupai_uid);
		if(tianhu) {
			//庄家赢100胡,其他玩家0胡
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==banker_uid) {
					score=100;
				}else {
					score=0;
				}
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
			hupai_data.getHu_types().add(HuType.TIANHU);
			return score_map;
		}
		boolean dihu=checkDihu(room,hupai_uid);
		if(dihu) {
			//庄家输100胡,胡牌玩家赢100胡,其他玩家0胡
			PlayerData op_data = phzGameBase.getPlayers().get(banker_uid);
			int out_count=op_data.getOut_count();
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==banker_uid) {
					if(out_count==0) {
						score=0;
					}else if(out_count==1) {
						score=-100;
					}
				}else if(uid==hupai_uid){
					score=100;
				}else {
					score=0;
				}
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
			hupai_data.getHu_types().add(HuType.DIHU);
			return score_map;
		}
		boolean yidianzhu=false;
		boolean honghu=false;
		boolean shisanhong=false;
		boolean wuhu=false;
		boolean yikuaibian=false;
		boolean haidihu=false;
		boolean sanshihu=false;
		boolean ershihu=false;
		yidianzhu=checkYidianzhu(room,hupai_uid);
		if(yidianzhu) {
		}else {
			honghu=checkHonghu(room,hupai_uid);
			if(honghu) {
			}else {
				shisanhong=checkShisanhong(room,hupai_uid);
				if(shisanhong) {
				}else {
					wuhu=checkWuhu(room,hupai_uid);
				}
			}
		}
		yikuaibian=checkYikuaibian(room,hupai_uid);
		sanshihu=checkSanshihu(room,hupai_uid);
		haidihu=checkHaidihu(room,hupai_uid);
		int zimo=checkZimo(room,hupai_uid);
		if(zimo==0) {
			hupai_data.getHu_types().add(HuType.PINGHU);
		}else if(zimo==1) {
			hupai_data.getHu_types().add(HuType.ZIMOHU);
		}else if(zimo==2) {
			hupai_data.getHu_types().add(HuType.DIANPAOHU);
		}
		
		if(!sanshihu) {
			ershihu=checkErshihu(room,hupai_uid);
		}
		
		if(yidianzhu) {
			hupai_data.getHu_types().add(HuType.YIDIANHONG);
		}
		if(honghu) {
			hupai_data.getHu_types().add(HuType.HONGHU);
		}
		if(shisanhong) {
			hupai_data.getHu_types().add(HuType.SHISANHONG);
		}
		if(wuhu) {
			hupai_data.getHu_types().add(HuType.WUHU);
		}
		if(yikuaibian) {
			if(!yidianzhu) {
				//一块匾和一点朱同时存在只算一点朱
				hupai_data.getHu_types().add(HuType.YIKUAIBIAN);
			}
		}
		if(haidihu) {
			hupai_data.getHu_types().add(HuType.HAIDIHU);
		}
		if(sanshihu) {
			hupai_data.getHu_types().add(HuType.SANSHIHU);
		}
		if(ershihu) {
			hupai_data.getHu_types().add(HuType.KAHU);
		}
		
		int win_score=0;
		int fanbei=1;
		if(yidianzhu) {
			fanbei*=2;
		}
		if(honghu) {
			fanbei*=2;
		}
		if(shisanhong) {
			win_score+=100;
		}
		if(wuhu) {
			win_score+=100;
		}
		if(yikuaibian) {
			if(!yidianzhu) {
				fanbei*=2;
			}
		}
		if(haidihu) {
			fanbei*=2;
		}
		if(sanshihu) {
			win_score+=100;
		}else if(ershihu) {
			fanbei*=2;
		}
		
		if(zimo==0) {
			//平胡(胡别人摸的牌,偎胡,跑胡,提胡),胡牌玩家分数增加,其他玩家分数0
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==hupai_uid){
					if(win_score==0) {
						score+=RoomUtil.calHuxiByPlayerData(room,playerData);
					}else {
						score+=win_score;
					}
					score*=fanbei;
				}else {
					score=0;
				}
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
		} else if(zimo==1) {
			//自摸(胡自己摸的牌)胡牌玩家分数增加,其他玩家分数0
			fanbei*=2;
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==hupai_uid){
					if(win_score==0) {
						score+=RoomUtil.calHuxiByPlayerData(room,playerData);
					}else {
						score+=win_score;
					}
					score*=fanbei;
				}else {
					score=0;
				}
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
		}else if(zimo==2) {
			//放炮(胡别人打的牌)胡牌玩家分数增加,放炮玩家分数减少(且分数最多100),其他玩家0
			int fangpao_uid=getFangpaoUid(room,hupai_uid);
			int temp_score=0;
			if(win_score==0) {
				temp_score+=RoomUtil.calHuxiByPlayerData(room,hupai_data);
			}else {
				temp_score+=win_score;
			}
			temp_score*=fanbei;
			temp_score=temp_score>=100?100:temp_score;
			for(PlayerData playerData:playerDatas.values()) {
				int uid=playerData.getUid();
				int score=0;
				if(uid==hupai_uid){
					score=temp_score;
				}else if(uid==fangpao_uid){
					score=-temp_score;
				}else {
					score=0;
				}
				if(phzConfig.getFengding()!=0) {
					score=score>=phzConfig.getFengding()?phzConfig.getFengding():score;
				}
				score_map.put(uid, score);
				int old=phzRoomCache.getTotal_score().get(uid)==null?0:phzRoomCache.getTotal_score().get(uid);
				phzRoomCache.getTotal_score().put(uid, old+score);
			}
		}
		return score_map;
	}

	private int getFangpaoUid(Room room, Integer hupai_uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		OpData opData = phzGameBase.getFanpai();
		if(opData.getUid()!=hupai_uid&&opData.getType()==OpType.OUTCARD) {
			return opData.getUid();
		}
		throw new RuntimeException("getFangpaoUid未知错误,检查逻辑代码");
	}

	private boolean checkErshihu(Room room, Integer hupai_uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(hupai_uid);
		int score=RoomUtil.calHuxiByPlayerData(room,playerData);
		if(score==20) {
			return true;
		}
		return false;
	}

	private boolean checkSanshihu(Room room, Integer hupai_uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(hupai_uid);
		int score=RoomUtil.calHuxiByPlayerData(room,playerData);
		if(score==30) {
			return true;
		}
		return false;
	}

	private boolean checkHaidihu(Room room, Integer hupai_uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		if(phzGameBase.getDipai().isEmpty()) {
			return true;
		}
		return false;
	}

	private boolean checkYikuaibian(Room room, Integer hupai_uid) {
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(hupai_uid);
		List<Data> baipais=playerData.getBaipais();
		Set<Integer> erqishi=new HashSet<>();
		erqishi.add(2);
		erqishi.add(7);
		erqishi.add(10);
		int count=0;
		for(Data data:baipais) {
			if(count>=2) {
				return false;
			}
			List<Card> cards=new ArrayList<>();
			if(data instanceof TipaiData) {
				TipaiData tipaiData = (TipaiData) data;
				cards.addAll(tipaiData.getTipailist());
			}else if(data instanceof PaopaiData) {
				PaopaiData paopaiData = (PaopaiData) data;
				cards.addAll(paopaiData.getPaopailist());
			}else if(data instanceof WeipaiData) {
				WeipaiData weipaiData = (WeipaiData) data;
				cards.addAll(weipaiData.getWeipailist());
			}else if(data instanceof ChouweiData) {
				ChouweiData chouweiData = (ChouweiData) data;
				cards.addAll(chouweiData.getChouweilist());
			}else if(data instanceof PengData) {
				PengData pengData = (PengData) data;
				cards.addAll(pengData.getPengpailist());
			}else if(data instanceof ChiData) {
				ChiData chiData = (ChiData) data;
				cards.addAll(chiData.getChipailist());
			}
			Set<Integer> nums=new HashSet<>();
			for(Card card:cards) {
				nums.add(card.getNum());
			}
			if(erqishi.containsAll(nums)) {
				count+=1;
			}else {
				if(nums.contains(2)||nums.contains(7)||nums.contains(10)) {
					count+=1;
				}
			}
			
		}
		HupaiData hupaiData = phzGameBase.getHupaiData();
		List<List<Card>> cardlists=hupaiData.getHupailist();
		for(List<Card> cards:cardlists) {
			if(count>=2) {
				return false;
			}
			Set<Integer> nums=new HashSet<>();
			for(Card card:cards) {
				nums.add(card.getNum());
			}
			if(erqishi.containsAll(nums)) {
				count+=1;
			}else{
				if(nums.contains(2)||nums.contains(7)||nums.contains(10)) {
					count+=1;
				}
			}
		}
		if(count==1) {
			return true;
		}
		return false;
	}

	private boolean checkWuhu(Room room, Integer hupai_uid) {
		List<Card> tmp=getAllCards(room,hupai_uid);
		return CardUtil.wuhu(tmp);
	}

	private boolean checkShisanhong(Room room, Integer hupai_uid) {
		List<Card> tmp=getAllCards(room,hupai_uid);
		return CardUtil.shisanhong(tmp);
	}

	private boolean checkHonghu(Room room, Integer hupai_uid) {
		List<Card> tmp=getAllCards(room,hupai_uid);
		return CardUtil.honghu(tmp);
	}

	private boolean checkYidianzhu(Room room, Integer hupai_uid) {
		List<Card> tmp=getAllCards(room,hupai_uid);
		return CardUtil.yidianzhu(tmp);
	}

	private List<Card> getAllCards(Room room, Integer hupai_uid) {
		List<Card> tmp=new ArrayList<>();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(hupai_uid);
		List<Data> baipais=playerData.getBaipais();
		List<Card> hands=playerData.getHands();
		tmp.addAll(hands);
		for(Data data:baipais) {
			List<Card> cards=new ArrayList<>();
			if(data instanceof TipaiData) {
				TipaiData tipaiData = (TipaiData) data;
				cards.addAll(tipaiData.getTipailist());
			}else if(data instanceof PaopaiData) {
				PaopaiData paopaiData = (PaopaiData) data;
				cards.addAll(paopaiData.getPaopailist());
			}else if(data instanceof WeipaiData) {
				WeipaiData weipaiData = (WeipaiData) data;
				cards.addAll(weipaiData.getWeipailist());
			}else if(data instanceof ChouweiData) {
				ChouweiData chouweiData = (ChouweiData) data;
				cards.addAll(chouweiData.getChouweilist());
			}else if(data instanceof PengData) {
				PengData pengData = (PengData) data;
				cards.addAll(pengData.getPengpailist());
			}else if(data instanceof ChiData) {
				ChiData chiData = (ChiData) data;
				cards.addAll(chiData.getChipailist());
			}
			tmp.addAll(cards);
		}
		return tmp;
	}

	private int checkZimo(Room room, Integer hupai_uid) {
		//0平胡(胡别人摸的牌,偎胡,跑胡,提胡) 1自摸(胡自己摸的牌) 2点炮(胡别人打的牌)
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		OpData hupai = phzGameBase.getHupai();
		if(hupai==null) {
			OpData fan=phzGameBase.getFanpai();
			if(fan.getBaipai_uid()!=null) {
				if(fan.getUid()==hupai_uid&&fan.getType()==OpType.MOPAI) {
					phzRoomCache.zimo_times_inc(hupai_uid);
					return 1;
				}
				if(fan.getUid()!=hupai_uid&&fan.getType()==OpType.OUTCARD) {
					phzRoomCache.dianpao_times_inc(fan.getUid());
					return 2;
				}
			}
			return 0;
		}
		if(hupai.getUid()!=hupai_uid) {
			if(hupai.getType()==OpType.MOPAI) {
				return 0;
			}else if(hupai.getType()==OpType.OUTCARD) {
				phzRoomCache.dianpao_times_inc(hupai.getUid());
				return 2;
			}
		}else {
			if(hupai.getType()==OpType.MOPAI) {
				phzRoomCache.zimo_times_inc(hupai_uid);
				return 1;
			}else {
				throw new RuntimeException("检查自摸未知错误,检查逻辑");
			}
		}
		return 0;
	}

	private boolean checkDihu(Room room,Integer hupai_uid) {
		PhzGameBase phzGameBase= (PhzGameBase) room.getGameBase();
		int banker_uid=phzGameBase.getBanker_uid();
		if(banker_uid!=hupai_uid) {
			PlayerData op_data = phzGameBase.getPlayers().get(banker_uid);
			int out_count=op_data.getOut_count();
			if(out_count<=1) {
				return true;
			}
		}
		return false;
	}

	private boolean checkTianhu(Room room,Integer hupai_uid) {
		PhzGameBase phzGameBase= (PhzGameBase) room.getGameBase();
		int banker_uid=phzGameBase.getBanker_uid();
		if(hupai_uid==banker_uid) {
			PlayerData player_data = phzGameBase.getPlayers().get(hupai_uid);
			int out_count=player_data.getOut_count();
			if(out_count==0) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void reqHupaiGuo(Room room, LogicController controller, ReqHupaiGuo reqHupaiGuo, int op) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		Map<Integer,List<CphOpData>> map=phzGameBase.getOplistmap();
		if(map.isEmpty()||!map.containsKey(uid)) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "当前不该你操作")));
			return;
		}
		if(map.containsKey(uid)) {
			Map<Integer, ReqOp>  choosemap=phzGameBase.getChoosemap();
			if(choosemap.containsKey(uid)) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.CANT_OPERATE, "已经做出选择")));
				return;
			}
		}
		List<CphOpData>cphOpDatas =map.get(uid);
		CphOpData cphOpData=RoomUtil.findCphOpDataByOp(op,cphOpDatas);
		if(cphOpData==null) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_CPHOP, Resp.build(Code.PARAM_ERROR, "参数错误,没有该操作")));
			return;
		}
		RoomUtil.reqHupaiGuo(room,controller,reqHupaiGuo);
	}

	@Override
	public void reqShootBird(Room room, LogicController controller, int bird) {
		if(bird<0) {
			return;
		}
		int room_times=room.getRoom_times();
		if(room_times!=0) {
			//当前不能打鸟
			return;
		}
		PhzConfig phzConfig=(PhzConfig) room.getGameConfig();
		if(phzConfig.getBird()==0) {
			//不允许打鸟
			return;
		}
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		if(phzRoomCache.getBirds().containsKey(controller.getId())) {
			//玩家已经打过鸟了
			return;
		}
		if(bird>phzConfig.getBird_max()) {
			//最大打30倍
			return;
		}
		phzRoomCache.getBirds().put(controller.getId(), bird);
		controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SHOOT_BIRD, Resp.build(Code.OK, "打鸟成功")));		
	}

	@Override
	public void reqSetcards(Room room, LogicController controller, List<Integer> cardIds) {
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		SetcardsPanel setcardsPanel = phzRoomCache.getSetcardsPanel();
		Map<Integer,List<Integer>> setsmap=setcardsPanel.getSetsmap();	
		Map<Integer,Integer> nummap=CardUtil.numMapByCardIds(cardIds);
		int total=0;
		List<Card> cards=CardUtil.phz();
		int uid=controller.getId();
		for(Entry<Integer,Integer> entry:nummap.entrySet()) {
			int card_id=entry.getKey();
			int num=entry.getValue();
			if(num>4) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SETCARDS, Resp.build(Code.PARAM_ERROR, "选择的牌大于4张,牌card_id:"+card_id)));
				return;
			}
			total+=num;
		}
		if(total!=20) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SETCARDS, Resp.build(Code.PARAM_ERROR, "必须选择20张")));
			return;
		}
		for(Integer card_id:nummap.keySet()) {
			Card card=CardUtil.findOneCardFromHandByCardId(cards, card_id);
			if(card==null) {
				controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SETCARDS, Resp.build(Code.PARAM_ERROR, "选择的牌找不到,牌card_id:"+card_id)));
				return;
			}
		}
		setsmap.put(uid, cardIds);
		controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SETCARDS, Resp.build(Code.OK, "设置牌成功,下局生效")));
	}

	@Override
	public void reqSetcardsLeft(Room room, LogicController controller) {
		PhzRoomCache phzRoomCache = (PhzRoomCache) room.getRoomCache();
		SetcardsPanel setcardsPanel = phzRoomCache.getSetcardsPanel();
		Map<Integer,List<Integer>> setsmap=setcardsPanel.getSetsmap();
		List<Integer> list=new ArrayList<>();
		for(List<Integer> tmp:setsmap.values()) {
			list.addAll(tmp);
		}
		
		List<Card> cards=CardUtil.phz();
		for(Integer card_id:list) {
			Card card=CardUtil.findOneCardFromHandByCardId(cards, card_id);
			if(card!=null) {
				cards.remove(card);
			}
		}
		Map<Integer,Integer> nummap=CardUtil.numMap(cards);
		controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_SETCARDS_LEFT, Resp.build(Code.OK, "拉取余下的牌成功",PackageUtil.packageResSetcardsLeft(nummap))));
	}

	@Override
	public void reqQihu(Room room, LogicController controller) {
		int room_status=room.getRoom_status();
		if(room_status!=RoomStatus.GAMING) {
			controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_QIHU, Resp.build(Code.CANT_OPERATE, "当前不能操作")));
			return;
		}
		int uid=controller.getId();
		PhzGameBase phzGameBase = (PhzGameBase) room.getGameBase();
		PlayerData playerData = phzGameBase.getPlayers().get(uid);
		if(playerData.isQihu()) {
			return;
		}
		RoomUtil.reqQihu(room, uid);
		controller.getWebClient().sendMessage(Message.build(PHZCMD.RES_QIHU, Resp.build(Code.OK, "弃胡成功")));
	}


}
